#!/usr/bin/python


filedir = '/tmp/awesome_metrics.log'

import sys

# open the tmp file to read and count metrics
with open(filedir, 'r') as f:
    count = {}
    for line in f.readlines():
        line = line.rstrip('\n')
        try:
            count[line] += 1
        except KeyError:
            count[line] = 1

# If config string is provided on command line
# then return graph details for munin.
if len(sys.argv) > 1 and sys.argv[1] == 'config':
    print 'graph_title HTTP requests'
    print 'graph_vlabel num reqs'
    print 'show_listget.label show_listget'
    print 'post.label post'
    print 'get.label get'

    sys.exit(0)

for k, v in count.items():
    print "{0}.value {1}".format(k.lower(), v)

# clear out the metrics that we've counted
f = open(filedir, 'w')
f.close()
